﻿var Query=fastCSharp.CreateQuery(self.location),HtmlEditor=parent.fastCSharp.Object[Query.id];
var Find=document.getElementById('Find');
Find.maxLength=200;
Find.onfocus=function()	{	this.select();	};
Find.onkeydown=function(E)
	{
	var Code=new fastCSharp.Functions.BrowserEvent(E||event).keyCode;
	if(Code==9||Code==13||Code==38||Code==40)
		{
		document.getElementById('Replace').focus();
		return false;
		}
	};
var Replace=document.getElementById('Replace');
Replace.maxLength=200;
Replace.onfocus=function()	{	this.select();	};
Replace.onkeydown=function(E)
	{
	var Event=new fastCSharp.Functions.BrowserEvent(E||event),Code=Event.shiftKey||Event.keyCode;
	if(Code==9||Code==38||Code==40)
		{
		document.getElementById('Find').focus();
		return false;
		}
	else if(Code==13)	document.getElementById('ReturnButton').onclick();
	};
document.getElementById('ReturnButton').onclick=function()
	{
	var Find=document.getElementById('Find').value,Replace=document.getElementById('Replace').value,IsDifferent=(document.getElementById('IsDifferent').checked?'g':'gi');
	if(Find){
		HtmlEditor.ShowOver();
		var Exp=new RegExp(HtmlEditor.IsDesign?Find.ToHTML():Find,IsDifferent);
		if(HtmlEditor.IsDesign)	HtmlEditor.PasteHtml(HtmlEditor.GetSelectionHtml(1).replace(Exp,Replace.ToHTML()),1);
		else	{
			HtmlEditor.Focus();
			HtmlEditor.PasteText(HtmlEditor.GetSelectionText(1).replace(Exp,Replace),true);
			}
		}
	else	{
		alert('查找串不能为空');
		document.getElementById('Find').focus();
		}
	};